/*    */ package blockbuster.components.motion;
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleInitialize;
/*    */ import blockbuster.components.IComponentParticleUpdate;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonArray;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ import javax.vecmath.Tuple3d;
/*    */ import javax.vecmath.Tuple3f;
/*    */ import javax.vecmath.Vector3f;
/*    */ 
/*    */ public class BedrockComponentMotionParametric extends BedrockComponentMotion implements IComponentParticleInitialize, IComponentParticleUpdate {
/* 18 */   public MolangExpression[] position = new MolangExpression[] { MolangParser.ZERO, MolangParser.ZERO, MolangParser.ZERO };
/* 19 */   public MolangExpression rotation = MolangParser.ZERO;
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 23 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 25 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 27 */     if (element.has("relative_position") && element.get("relative_position").isJsonArray()) {
/* 28 */       JsonArray array = element.get("relative_position").getAsJsonArray();
/*    */       
/* 30 */       this.position[0] = parser.parseJson(array.get(0));
/* 31 */       this.position[1] = parser.parseJson(array.get(1));
/* 32 */       this.position[2] = parser.parseJson(array.get(2));
/*    */     } 
/*    */     
/* 35 */     if (element.has("rotation")) {
/* 36 */       this.rotation = parser.parseJson(element.get("rotation"));
/*    */     }
/*    */     
/* 39 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 44 */     JsonObject object = new JsonObject();
/* 45 */     JsonArray position = new JsonArray();
/*    */     
/* 47 */     for (MolangExpression expression : this.position) {
/* 48 */       position.add(expression.toJson());
/*    */     }
/*    */     
/* 51 */     object.add("relative_position", (JsonElement)position);
/*    */     
/* 53 */     if (!MolangExpression.isZero(this.rotation)) object.add("rotation", this.rotation.toJson());
/*    */     
/* 55 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */   
/*    */   public void apply(BedrockEmitter emitter, BedrockParticle particle) {
/* 60 */     Vector3f position = new Vector3f((float)this.position[0].get(), (float)this.position[1].get(), (float)this.position[2].get());
/*    */     
/* 62 */     particle.manual = true;
/* 63 */     particle.initialPosition.set((Tuple3d)particle.position);
/*    */     
/* 65 */     particle.matrix.transform((Tuple3f)position);
/* 66 */     particle.position.x = particle.initialPosition.x + position.x + emitter.extraX;
/* 67 */     particle.position.y = particle.initialPosition.y + position.y + emitter.extraY;
/* 68 */     particle.position.z = particle.initialPosition.z + position.z + emitter.extraZ;
/* 69 */     particle.rotation = (float)this.rotation.get();
/*    */   }
/*    */ 
/*    */   
/*    */   public void update(BedrockEmitter emitter, BedrockParticle particle) {
/* 74 */     Vector3f position = new Vector3f((float)this.position[0].get(), (float)this.position[1].get(), (float)this.position[2].get());
/*    */     
/* 76 */     particle.matrix.transform((Tuple3f)position);
/* 77 */     particle.position.x = particle.initialPosition.x + position.x + emitter.extraX;
/* 78 */     particle.position.y = particle.initialPosition.y + position.y + emitter.extraY;
/* 79 */     particle.position.z = particle.initialPosition.z + position.z + emitter.extraZ;
/* 80 */     particle.rotation = (float)this.rotation.get();
/*    */   }
/*    */ 
/*    */   
/*    */   public int getSortingIndex() {
/* 85 */     return 10;
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\motion\BedrockComponentMotionParametric.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */